﻿using AutoMapper;
using Net8.Project.Common;
using Net8.Project.Common.Extensions;
using Net8.Project.Data;
using Net8.Project.IService;
using Net8.Project.Model.Dto;
using Net8.Project.Model.Entity;

namespace Net8.Project.Service.Services
{
    public class DepartmentService : BaseService<Department>, IDepartmentService
    {
        private readonly IBaseRepository<Department> _dal;
        public DepartmentService(
            IMapper mapper, IBaseRepository<Department> baseRepository) : base(mapper, baseRepository)
        {
            _dal = baseRepository;
        }

        [UseTran(Propagation = Propagation.Required)]
        public async Task<bool> TestTranPropagation2()
        {
            TimeSpan timeSpan = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var id = timeSpan.TotalSeconds.ObjToLong();
            var insertDepartment = await _dal.Add(new Department()
            {
                Id = id,
                Name = $"department name {id}",
                CodeRelationship = "",
                OrderSort = 0,
                Status = true,
                IsDeleted = false,
                Pid = 0
            });

            await Console.Out.WriteLineAsync($"db context id : {base.Db.ContextID}");

            return true;
        }
    }
}
